package study.datastructure.order.recursion;/**
 * @program: datastructure
 * @author: lcy
 * @create: 2024-09-26 14:50
 */

/**
 2024/9/26,
 */

//递归冒泡排序
public class BubbleSort {
    public static void sort(int[]a){
        v1bubble(a,a.length-1);
    }
    public static void sort2(int[]a){
        v2bubble(a,a.length-1);
    }

    //j代表右边界范围
    private static void v1bubble(int[]a, int j){
        if (j==0) {
            return;
        }
        for (int i = 0; i < j; i++) {
            if (a[i]>a[i+1]) {
                int t=a[i];
                a[i]=a[i+1];
                a[i+1] = t;
            }
        }
        v1bubble(a,j-1);
    }
private static void v2bubble(int[]a, int j){
    if (j==0) {
        return;
    }
    int x=0;
    for (int i = 0; i < j; i++) {
        if (a[i]>a[i+1]) {
            int t=a[i];
            a[i]=a[i+1];
            a[i+1] = t;
            x=i;
        }
    }
    v1bubble(a,x);
}

}
